<?php

namespace models;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity
 * @Entity @Table(name="blog_post")
 *
 * */

class Post {

   
    public function __construct(User $user = NULL, Category $category = NULL) {


        $this->author = $user;
        $this->category = $category;
        
         $this -> comments = new ArrayCollection;
         
 
    }
    
   

    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @OneToMany(targetEntity="Comment", mappedBy="post",
     *   cascade={"persist"})
     **/
    private $comments;
    
    /**
     * @Column(type="string")
     **/   
    
    private $title;
    /**
     * @Column(type="string")
     **/
     
      private $short_description;
    /**
     * @Column(type="string")
     **/
     
    private $article;
    /**
     * @Column(type="string")
     **/
    private $title_clean;
    /**
     * @Column(type="string")
     **/
    private $file;
     /**
     * @ManyToOne(targetEntity="User", inversedBy="posts")
     **/
    private $author;
    /**
     * @Column(type="datetime")
     **/
    private $date_published;
    /**
     * @Column(type="string")
     **/
    private $banner_image;
    /**
     * @Column(type="boolean")
     **/
    private $featured;
    /**
     * @Column(type="boolean")
     **/
    private $enabled;
    /**
     * @Column(type="boolean")
     **/
    private $comments_enabled;
    /**
     * @Column(type="integer")
     **/
    private $views;
    /**
     * @Column(type="datetime")
     **/
    private $date_last_update;
    /**
     * @ManyToOne(targetEntity="Category")
     **/
    private $category;
    
    
    public function getId() {
        return $this -> id;
    }

    public function setTitle($value) {
        $this -> title = $value;
    }

    public function getTitle() {
        return $this -> title;
    }
    
    
     public function setArticle($value) {
        $this -> article= $value;
    }

    public function getArticle() {
        return $this -> article;
    }
    
	   public function setShortDescription($value) {
        $this ->  short_description = $value;
    }

    public function getShortDescription() {
        return $this -> short_description;
    }
	
    
     public function setTitleClean($value) {
        $this -> title_clean = $value;
    }

    public function getTitleClean() {
        return $this -> title_clean;
    }
    
    
     public function setFile($value) {
        $this -> file = $value;
    }

    public function getFile() {
        return $this -> file;
    }
    
    public function setAuthor($value) {
        $this -> author = $value;
    }

    public function getAuthor() {
        return $this -> author;
    }
    
     public function setDatePublished($value) {
        $this -> date_published = $value;
    }

    public function getDatePublished() {
        return $this -> date_published;
    }
    
     public function setBannerImage($value) {
        $this -> banner_image = $value;
    }

    public function getBannerImage() {
        return $this -> banner_image;
    }
    
     public function setFeatured($value) {
        $this -> featured = $value;
    }

    public function isFeatured() {
        return $this -> featured;
    }
    
    public function setEnabled($value) {
        $this -> enabled = $value;
    }

    public function isEnabled() {
        return $this -> enabled;
    }
    
    public function setCommentsEnabled($value) {
        $this -> comments_enabled = $value;
    }

    public function areCommentsEnabled() {
        return $this -> comments_enabled;
    }
    
    public function setViews($value) {
        $this -> views= $value;
    }

    public function getViews() {
        return $this -> views;
    }
    
    public function setLastUpdate($value) {
        $this -> date_last_update = $value;
    }

    public function getLastUpdate() {
        return $this ->date_last_update;
    }
    
   public function setCategory($value) {
        $this -> category = $value;
    }

    public function getCategory() {
        return $this ->category;
    }
    
    
        public function getComments() {
        return $this ->comments;
    }
    
    
  
    public static function prepareData(array $data, Post &$post) {
         
        $post->setTitle($data['title']);
        $post->setArticle($data['article']);
		$post->setShortDescription($data['short_description']);
        $post->setFile($data['file']);
        $post->setViews(0);
        $post->setTitleClean($data['title_clean']);
        $post->setFeatured((isset($data['featured']) == null) ? 0 : 1);
        $post->setEnabled((isset($data['enabled']) == null) ? 0 : 1);
        $post->setCommentsEnabled((isset($data['enabled']) == null) ? 0 : 1);
   
    }   
    
    
    public function addComment($text)
    {
        $this->comments[] = new Comment($this, $text);
    } 
    

}
